package be.dch.gui.panels;

import javax.swing.Icon;
import javax.swing.JFileChooser;

import be.dch.gui.components.JTextFieldBrowse;
import be.dch.gui.layout.RegexFileFilter;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

public final class LocationPanel extends AbstractPanel {

    private static final long serialVersionUID = 3700206799787429747L;

    private static LocationPanel instance = new LocationPanel();

    private static final String COLUMN_SPECS = "1dlu:grow,50dlu,3dlu,150dlu,3dlu,50dlu,3dlu,50dlu,1dlu:grow";
    private static final String ROW_SPECS = "pref,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,15dlu,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref,3dlu,pref:grow";

    private LocationPanel() {
	super();
	final FormLayout layout = new FormLayout(LocationPanel.COLUMN_SPECS, LocationPanel.ROW_SPECS);

	final CellConstraints constraints = new CellConstraints();

	final PanelBuilder builder = new PanelBuilder(layout);

	final JTextFieldBrowse txtTypEditor = new JTextFieldBrowse("Type Editor:", this, JFileChooser.FILES_ONLY);
	txtTypEditor.setFileFilter(new RegexFileFilter(".*.exe", ".exe"));
	builder.add(txtTypEditor.getLabel(), constraints.rchw(3, 2, 1, 1));
	builder.add(txtTypEditor.getTextField(), constraints.rchw(3, 4, 1, 1));
	builder.add(txtTypEditor.getButton(), constraints.rchw(3, 6, 1, 1));

	final JTextFieldBrowse txtSrtm2Osm = new JTextFieldBrowse("Srtm To Osm", this, JFileChooser.FILES_ONLY);
	txtSrtm2Osm.setFileFilter(new RegexFileFilter(".*Srtm2Osm.exe", "Srtm2Osm.exe"));
	builder.add(txtSrtm2Osm.getLabel(), constraints.rchw(5, 2, 1, 1));
	builder.add(txtSrtm2Osm.getTextField(), constraints.rchw(5, 4, 1, 1));
	builder.add(txtSrtm2Osm.getButton(), constraints.rchw(5, 6, 1, 1));

	this.add(builder.getPanel());

    }

    /**
     * 
     * @return locationPanel
     */
    public static LocationPanel getInstance() {
	return LocationPanel.instance;
    }

    @Override
    public String getPanelTitle() {
	return "External locations";
    }

    @Override
    public Icon getPanelIcon() {
	return this.createImageIcon("/images/file-externallocation-icon.png", "External Locations");

    }

}
